<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图书-书单管理</title>
    <link rel="icon" href="/static/images/t_logo.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/static/css/lyk-global.css" />
    <link rel="stylesheet" href="/static/elementui/lib/theme-chalk/index.css">
    <script src="/static/js/jquery.min.js" type="text/javascript"></script>
    <script src="/static/js/requestApi.js" type="text/javascript"></script>
    <script src="/static/js/vue/vue.js"></script>
    <!-- 引入elementui -->
    <script src="/static/elementui/js/element.js"></script>
    <script src="/static/js/axios.min.js"></script>
    <script src="/static/js/axios-config.js"></script>
    <script src="/static/js/utilJs.js"></script>
</head>
<style>
    *{
        font-size: 14px
    }
    [v-cloak] {
        display: none;
    }
</style>
<body style="background-color: #fff">
<div id="app" v-cloak>
    <div class="mt-8 ml-4">
        <el-input placeholder="请输入书籍名称" size="small" style="width:200px;" class="ml-2" v-model="queryParam.bookName" @keyup.native.enter="getTableDataMethod(true)"></el-input>
        <el-button type="primary" size="small" class="ml-2" @click="getTableDataMethod(true)">搜索</el-button>
        <el-table :data="tableData" v-loading="tableDataLoading" class="mt-4">
            <el-table-column prop="id" label="书籍编号" width="150"></el-table-column>
            <el-table-column prop="bookName" label="名称"></el-table-column>
            <el-table-column prop="typeName" label="书籍类型"></el-table-column>
            <el-table-column prop="author" label="作者"></el-table-column>
            <el-table-column prop="publish" label="出版社"></el-table-column>
            <el-table-column prop="isbn" label="isbn"></el-table-column>
<!--            <el-table-column prop="stock" label="库存"></el-table-column>-->
            <el-table-column prop="picUrl" label="封面">
                <template slot-scope="scope">
                    <img :src="'/book/getLocalSystemPic?filePath=' + scope.row.picUrl" alt="Smiley face" width="42" height="42" v-if="scope.row.picUrl">
                </template>
            </el-table-column>

            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-popconfirm :title='"是否删除该条数据？"'
                                   @confirm="deleteBookCollectionMethod(scope.row)">
                        <el-button slot="reference" type="danger" size="small" v-loading="deleteLoading"  class="mt-2">删除</el-button>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background layout="total,sizes,prev, pager, next" :total="tableDataPaging.total"
                       :page-sizes="[10, 20, 50]"
                       prev-text="上一页" next-text="下一页"
                       :page-size="tableDataPaging.pageSize"
                       :current-page="tableDataPaging.currentPage"
                       @current-change="tableDataPagingChange"
                       @prev-click="tableDataPagingChange" @next-click="tableDataPagingChange"
                       @size-change="tableDataPagingSizeChange"
                       style="float:right;margin-top: 40px;padding-bottom:50px;">
        </el-pagination>

    </div>

</div>
</body>

<script type="text/javascript">
    const vm = new Vue({ // 配置对象 options
        // 配置选项(option)
        el: '#app', // element: 指定用vue来管理页面中的哪个标签区域
        components: {
        },
        data() {
            return {
                queryParam : {
                    bookName:"",
                    typeId:"",
                    isbn:"",
                    ticketNumber:""
                },
                tableData : [],
                tableDataLoading : false,
                tableDataPaging : {
                    currentPage : 1,
                    pageSize : 10,
                    total : 0,
                },
                deleteLoading:false,

            }
        },
        mounted() {
            let that = this;
            this.$nextTick(function () {
                that.getTableDataMethod();
            });
        },
        methods: {
            tableDataPagingChange(val) {
                let that = this;
                that.tableDataPaging.currentPage = val;
                that.getTableDataMethod();
            },
            tableDataPagingSizeChange(val) {
                let that = this;
                that.tableDataPaging.pageSize = val;
                that.getTableDataMethod();
            },
            //获取表格的数据
            getTableDataMethod(isChongZhi){
                let that = this;
                if (isChongZhi) {
                    this.tableDataPaging.currentPage = 1;
                }
                const {bookName,isbn,ticketNumber} = this.queryParam
                let queryData = {
                    bookName: $.trim(bookName),
                    isbn: $.trim(isbn),
                    ticketNumber: $.trim(ticketNumber),
                    pageNum: this.tableDataPaging.currentPage,
                    pageSize: this.tableDataPaging.pageSize,
                }
                this.tableDataLoading = true;
                that.tableData = [];
                requestApiTB("book/collection/getBookCollectionList",queryData,'post',function (res){
                    that.tableDataLoading = false;
                    if (res.code === 0) {
                        that.tableData = res.data.list;
                        that.tableDataPaging.total = res.data.total;
                    }else{
                        that.$message.error("error");
                    }
                });
            },
            deleteBookCollectionMethod(row){
                let that = this;
                if(!row.id){
                    return;
                }
                that.tableDataLoading = true;
                requestApiTB("book/collection/delBookCollectionById",{"id":row.id},'post',function (res){
                    that.tableDataLoading = false;
                    if (res.code === 0) {
                        that.$message.success("删除成功");
                      that.getTableDataMethod(true);
                    }else{
                        that.$message.error("error");
                    }
                });

            },
        }
    })
</script>
</html>